/**
 * json配置举例，更多配置请看 IConfigSchema
 * @author luguoxiang
 * @date 2022/7/5
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
import { RadioGroup } from 'tdesign-vue-next';
import { has, IConfigSchema, LgBizSelect, LgBizSelectProps, LgUploadProps } from '@/soar';
import userApi from '@/pages/auth/user/api';

const fieldList: IConfigSchema<any>[] = [
  {
    field: 'image',
    label: '图片',
    dataType: 'img',
    params: 'url' as LgUploadProps['valueType'],
    search: false,
    table: {
      width: 60,
    },
  },
  {
    field: 'file',
    label: '附件',
    dataType: 'file',
    search: false,
    table: false,
  },
  {
    field: 'string',
    label: '字符串',
    dataType: 'string',
    table: {
      width: 100,
      sorter: true,
    },
    form: {
      rules: true, // true方式配置校验，必填
    },
  },
  {
    field: 'number',
    label: '数值',
    dataType: 'number',
    table: {
      width: 80,
    },
    form: {
      rules: '字符串方式配置校验', // 字符串方式配置校验，必填
    },
  },
  {
    field: 'datetime',
    label: '日期时间',
    dataType: 'datetime',
    table: {
      width: 160,
    },
    form: {
      rules: [{ required: true, message: '数组方式配置校验', trigger: 'blur' }], // 常规方式配置校验
    },
  },
  {
    field: 'date',
    label: '日期',
    dataType: 'date',
    params: 'YYYY年MM年DD日',
    table: {
      width: 140,
    },
    form: {
      rules: (params) => {
        console.log(params);
        return [{ required: true, message: '动态函数方式配置', trigger: 'blur' }]; // 动态函数方式配置
      },
    },
  },
  {
    field: 'time',
    label: '时间',
    dataType: 'time',
    table: {
      width: 75,
    },
  },
  {
    field: 'boolean1',
    label: '布尔值默认',
    dataType: 'boolean',
  },
  {
    field: 'boolean2',
    label: '布尔值配置',
    dataType: 'boolean',
    params: '启用,禁用',
  },
  {
    field: 'dict',
    label: '数据字典',
    dataType: 'dict',
    params: 'UserTypeEnum',
    table: {
      width: 120,
    },
  },
  {
    field: 'remote',
    label: '远程',
    dataType: 'string',
    form: {
      component: LgBizSelect,
      componentProps: {
        placeholder: '请选择${label}',
        data: userApi.query,
        fields: 'id,nickname',
      } as LgBizSelectProps,
    },
    search: {
      component: LgBizSelect,
      componentProps: {
        placeholder: '请选择${label}',
        data: userApi.query,
        fields: 'id,nickname',
      } as LgBizSelectProps,
    },
  },
  {
    field: 'enum1',
    label: '字符串枚举1',
    dataType: 'enum',
    params: '选项A,选项B,选项C', // 字符串配置选项，值是索引
    form: {
      component: RadioGroup, // 使用导入组件
      formItemProps: {
        help: '帮助说明',
      },
    },
  },
  {
    field: 'enum2',
    label: '字符串枚举2',
    dataType: 'enum',
    params: 'a:选项A,b:选项B,c:选项C', // 字符串配置选项和值
    form: {
      component: 't-select', // 使用全局组件
      componentProps: {
        // eslint-disable-next-line no-template-curly-in-string
        placeholder: '请选择${label}',
      },
    },
  },
  {
    field: 'enum3',
    label: '数组枚举1',
    dataType: 'enum',
    params: ['选项A', '选项B', '选项C'], // 数组配置选项，值是索引
  },
  {
    field: 'enum4',
    label: '数组枚举2',
    dataType: 'enum',
    params: ['a:选项A', 'b:选项B', 'c:选项C'], // 数组配置选项和值
  },
  {
    field: 'enum5',
    label: '数组枚举3',
    dataType: 'enum',
    params: [
      // 最终选项格式配置
      { value: 0, label: '选项A' },
      { value: 1, label: '选项B' },
      { value: 2, label: '选项C' },
      { value: 3, label: '选项D', disabled: true },
    ],
  },
  {
    field: 'enum6',
    label: '对象kv枚举',
    dataType: 'enum',
    params: {
      // 键值对配置选项
      a: '选项A',
      b: '选项B',
      c: '选项C',
    },
  },
  {
    field: 'slot1',
    label: '插槽使用1',
    search: {
      slots: 'search1',
    },
    table: {
      slots: 'table1',
      width: 100,
    },
    form: {
      slots: 'form1',
    },
    detail: {
      slots: 'detail1',
    },
  },
  {
    field: 'slot2',
    label: '插槽使用2',
    search: {
      slots: {
        default: 'search2',
        label: 'search2-label',
        tips: 'search2-error',
      },
    },
    table: {
      slots: {
        default: 'table2',
        title: 'title',
      },
      width: 120,
    },
    form: {
      slots: {
        default: 'form2',
        label: 'form2-label',
        tips: 'form2-error',
      },
    },
    detail: {
      slots: {
        default: 'detail2',
        label: 'detail2-label',
      },
    },
  },
  {
    field: 'predicate',
    label: '权限控制',
    predicate(): boolean {
      // 只有admin角色 和 超级管理员用户可见的字段
      return has.role('admin');
    },
    componentProps: {
      placeholder: 'admin角色 和 超级管理员用户可见',
    },
    table: {
      width: 280,
    },
  },
];
/*
for (let i = 0; i < 100; i++) {
  fieldList.push({
    field: `field${i}`,
    label: `字段${i}`,
    form: {
      hidden({ data }) {
        return data?.string?.length % 2 === 0;
      },
      rules: [{ required: true, message: '请输入昵称' }],
    },
  });
} */

export default fieldList;
